Querystring search on array elements in Elastic Search

后端 未结 3 1039
孤独总比滥情好
孤独总比滥情好 2020-12-12 22:40

I\'m trying to learn elasticsearch with a simple example application, that lists quotations associated with people. The example mapping might look like:

{ 
          


        
3条回答
  •  感动是毒
    2020-12-12 23:07

    For that requirement to be achieved, you need to look at nested objects, not to query a flattened list of values but individual values from that nested object. For example:

    {
      "mappings": {
        "people": {
          "properties": {
            "name": {
              "type": "string"
            },
            "quotations": {
              "type": "nested",
              "properties": {
                "value": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
    

    Values:

    {"name":"Mr A","quotations":[{"value": "quotation one, this and that and these"}, {"value": "quotation two, those and that"}]}
    {"name":"Mr B","quotations":[{"value": "quotation three, this and that"}, {"value": "quotation four, those and these"}]}
    

    Query:

    {
      "query": {
        "nested": {
          "path": "quotations",
          "query": {
            "bool": {
              "must": [
                { "match": {"quotations.value": "this"}},
                { "match": {"quotations.value": "these"}}
              ]
            }
          }
        }
      }
    }
    

提交回复
热议问题