0

I'm really new to Elastic Search, and now blocked by one problem.

If I use GET http://127.0.0.1:9200/index/type/_search, the result is

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 3,
    "max_score": 1,
    "hits": [
      {
        "_index": "index",
        "_type": "type",
        "_id": "AVe3AcpYbUIbMIPUYcZ2",
        "_score": 1,
        "_source": {
          "applications": [
            {
              "jobs": [
                {
                  "id": 1,
                  "country": "a"
                },
                {
                  "id": 2,
                  "country": "b"
                }
              ]
            },
            {
              "jobs": [
                {
                  "id": 3,
                  "country": "c"
                },
                {
                  "id": 4,
                  "country": "d"
                }
              ]
            }
          ]
        }
      },
      {
        "_index": "index",
        "_type": "type",
        "_id": "AVe3cMaPbUIbMIPUYcaS",
        "_score": 1,
        "_source": {
          "applications": [
            {
              "jobs": [
                {
                  "id": 11,
                  "country": "aa"
                },
                {
                  "id": 2,
                  "country": "aa"
                }
              ]
            },
            {
              "jobs": [
                {
                  "id": 33,
                  "country": "aa"
                },
                {
                  "id": 44,
                  "country": "aa"
                }
              ]
            }
          ]
        }
      },
      {
        "_index": "index",
        "_type": "type",
        "_id": "AVe3b1KmbUIbMIPUYcaR",
        "_score": 1,
        "_source": {
          "applications": [
            {
              "jobs": [
                {
                  "id": 11,
                  "country": "aa"
                },
                {
                  "id": 2,
                  "country": "bb"
                }
              ]
            },
            {
              "jobs": [
                {
                  "id": 33,
                  "country": "cc"
                },
                {
                  "id": 44,
                  "country": "d"
                }
              ]
            }
          ]
        }
      }
    ]
  }
}

what I want is to get one application that every job.country in the application is "aa", so the expected result is

"applications": [
            {
              "jobs": [
                {
                  "id": 11,
                  "country": "aa"
                },
                {
                  "id": 2,
                  "country": "aa"
                }
              ]
            },
            {
              "jobs": [
                {
                  "id": 33,
                  "country": "aa"
                },
                {
                  "id": 44,
                  "country": "aa"
                }
              ]
            }
          ]

What I have tried is POST http://127.0.0.1:9200/index/type/_search

{
    "query": {
        "match": {
            "applications.jobs.country": "aa"
        }
    }
}

But the result is

{
  "took": 65,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0.30685282,
    "hits": [
      {
        "_index": "index",
        "_type": "type",
        "_id": "AVe3cMaPbUIbMIPUYcaS",
        "_score": 0.30685282,
        "_source": {
          "applications": [
            {
              "jobs": [
                {
                  "id": 11,
                  "country": "aa"
                },
                {
                  "id": 2,
                  "country": "aa"
                }
              ]
            },
            {
              "jobs": [
                {
                  "id": 33,
                  "country": "aa"
                },
                {
                  "id": 44,
                  "country": "aa"
                }
              ]
            }
          ]
        }
      },
      {
        "_index": "index",
        "_type": "type",
        "_id": "AVe3b1KmbUIbMIPUYcaR",
        "_score": 0.15342641,
        "_source": {
          "applications": [
            {
              "jobs": [
                {
                  "id": 11,
                  "country": "aa"
                },
                {
                  "id": 2,
                  "country": "bb"
                }
              ]
            },
            {
              "jobs": [
                {
                  "id": 33,
                  "country": "cc"
                },
                {
                  "id": 44,
                  "country": "d"
                }
              ]
            }
          ]
        }
      }
    ]
  }
}

It seems that if application contains a applications.jobs.country meet to the requirements ,it will be returned. and I want to get those every item in applications.jobs meets to need. anybody can help me? thanks

1 Answer 1

1

I use to regex to solve this problem temporarily. POST http://127.0.0.1:9200/index/type/_search

{
    "query": {
        "bool": {
            "must_not": {
                "regexp": {
                    "applications.jobs.country": "~(.*aa.*)"
                }
            }
        }
    }
}

must not contains that applications.jobs.country contains other than "aa"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.