我正在尝试使用一个简单的示例应用程序来学习elasticsearch,该应用程序列出了与人相关的引用.示例映射可能如下所示:
{
"people" : {
"properties" : {
"name" : { "type" : "string"},
"quotations" : { "type" : "string" }
}
}
}
Run Code Online (Sandbox Code Playgroud)
一些示例数据可能如下所示:
{ "name" : "Mr A",
"quotations" : [ "quotation one, this and that and these"
, "quotation two, those and that"]
}
{ "name" : "Mr B",
"quotations" : [ "quotation three, this and that"
, "quotation four, those and these"]
}
Run Code Online (Sandbox Code Playgroud)
我希望能够在个别引用上使用查询字符串api,并返回匹配的人.例如,我可能想要找到包含(这个和这些)的报价的人 - 应该返回"A先生"而不是"B先生",依此类推.我怎样才能做到这一点?
EDIT1:
Andrei在下面的回答似乎有效,数据值现在看起来像:
{"name":"Mr A","quotations":[{"value" : "quotation one, this and that …Run Code Online (Sandbox Code Playgroud) 我一直在研究Persistent库与sql数据库的接口.假设我有一个包含食谱的数据库,包括Recipe,Ingredient和RecIng表.
我对(持续有限的)对持久性的理解使我相信我应该像这样定义表:
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Recipe
title String
Ingredient
name String
RecIng
recId RecipeId
ingId IngredientId
quantity Int
|]
Run Code Online (Sandbox Code Playgroud)
有了这个,就可以使用Esqueleto来获取这些表之间的内部联接:
select $
from $ \(i `InnerJoin ` ri `InnerJoin` r) -> do
on (r ^. RecipeId ==. ri ^. RecIngIngId)
on (i ^. IngredientId ==. ri ^. RegIngRecId)
return (r, ri, i)
Run Code Online (Sandbox Code Playgroud)
这将返回(Recipe,RecIng,Ingredient)的元组.
我真正想要的是一种查询导致以下结果的食谱的方法:
data Recipe = Recipe { title :: String
, ingredients :: [Ingredient]
}
data Ingredient = Ingredient { name :: String
, quantity …Run Code Online (Sandbox Code Playgroud) 我试图通过任何一个字符串分隔",",", and"并且"and",然后返回无论是之间英寸 我到目前为止的一个例子如下:
import Data.Attoparsec.Text
sepTestParser = nameSep ((takeWhile1 $ inClass "-'a-zA-Z") <* space)
nameSep p = p `sepBy` (string " and " <|> string ", and" <|> ", ")
main = do
print $ parseOnly sepTestParser "This test and that test, this test particularly."
Run Code Online (Sandbox Code Playgroud)
我希望输出["This test", "that test", "this test particularly."].我有一种模糊的感觉,我正在做的事情是错的,但我无法理解为什么.