Filters with dynamic fields in elasticsearch
I am switching a very old version of ElasticSearch to version 6.5.
...
"text_mined_entities": {
"nlp": {
"abbreviations": ,
"chunks": ,
"recurring_chunks": ,
"tagged_entities_grouped": {
"NEURO|SCICRUNCH": [
{
"category": "NEURO",
"end": 41,
"label": "Infant",
"match": "infant",
"original_value": "Infant",
"reference": "BIRNLEX695",
"reference_db": "SCICRUNCH",
"sentence": 0,
"start": 35
},
...
I am wanting to filter on the text_mined_entities.nlp.tagged_entities_grouped.*.reference fields ( which are stored as 'keyword' ), but haven't had much luck. Something like:
GET _search
{
"query": {
"bool": {
"filter": { "term": {
"text_mined_entities.nlp.tagged_entities_grouped.*.reference": "BIRNLEX695"
}}
}
}
}
Any suggestions? Thanks.
elasticsearch elasticsearch-6
add a comment |
I am switching a very old version of ElasticSearch to version 6.5.
...
"text_mined_entities": {
"nlp": {
"abbreviations": ,
"chunks": ,
"recurring_chunks": ,
"tagged_entities_grouped": {
"NEURO|SCICRUNCH": [
{
"category": "NEURO",
"end": 41,
"label": "Infant",
"match": "infant",
"original_value": "Infant",
"reference": "BIRNLEX695",
"reference_db": "SCICRUNCH",
"sentence": 0,
"start": 35
},
...
I am wanting to filter on the text_mined_entities.nlp.tagged_entities_grouped.*.reference fields ( which are stored as 'keyword' ), but haven't had much luck. Something like:
GET _search
{
"query": {
"bool": {
"filter": { "term": {
"text_mined_entities.nlp.tagged_entities_grouped.*.reference": "BIRNLEX695"
}}
}
}
}
Any suggestions? Thanks.
elasticsearch elasticsearch-6
add a comment |
I am switching a very old version of ElasticSearch to version 6.5.
...
"text_mined_entities": {
"nlp": {
"abbreviations": ,
"chunks": ,
"recurring_chunks": ,
"tagged_entities_grouped": {
"NEURO|SCICRUNCH": [
{
"category": "NEURO",
"end": 41,
"label": "Infant",
"match": "infant",
"original_value": "Infant",
"reference": "BIRNLEX695",
"reference_db": "SCICRUNCH",
"sentence": 0,
"start": 35
},
...
I am wanting to filter on the text_mined_entities.nlp.tagged_entities_grouped.*.reference fields ( which are stored as 'keyword' ), but haven't had much luck. Something like:
GET _search
{
"query": {
"bool": {
"filter": { "term": {
"text_mined_entities.nlp.tagged_entities_grouped.*.reference": "BIRNLEX695"
}}
}
}
}
Any suggestions? Thanks.
elasticsearch elasticsearch-6
I am switching a very old version of ElasticSearch to version 6.5.
...
"text_mined_entities": {
"nlp": {
"abbreviations": ,
"chunks": ,
"recurring_chunks": ,
"tagged_entities_grouped": {
"NEURO|SCICRUNCH": [
{
"category": "NEURO",
"end": 41,
"label": "Infant",
"match": "infant",
"original_value": "Infant",
"reference": "BIRNLEX695",
"reference_db": "SCICRUNCH",
"sentence": 0,
"start": 35
},
...
I am wanting to filter on the text_mined_entities.nlp.tagged_entities_grouped.*.reference fields ( which are stored as 'keyword' ), but haven't had much luck. Something like:
GET _search
{
"query": {
"bool": {
"filter": { "term": {
"text_mined_entities.nlp.tagged_entities_grouped.*.reference": "BIRNLEX695"
}}
}
}
}
Any suggestions? Thanks.
elasticsearch elasticsearch-6
elasticsearch elasticsearch-6
asked Nov 24 '18 at 22:26
fitzfitz
2013
2013
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Wildcard on fields can't be applied on term query. Instead you can use query_string which supports wildcard on field as well. So following will work:
Assuming text_mined_entities and nlp are of type nested
{
"query": {
"nested": {
"path": "text_mined_entities.nlp",
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
}
}
Update (if text_mined_entities & nlp are object type and not nested):
{
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
Thanks! I changed my mapping to be "nested" for both text_mined_entities and nlp ( they were previously "object" ) and that query works. However, would it be possible in the mapping to only index the 'reference' field? It looks like setting this as nested is causing the index size to go up quite a bit.
– fitz
Nov 25 '18 at 12:18
I have added an update with query which should work if the fields areobjecttype. Regarding the possibility to index onlyreferencefield via mapping refer dynamic mapping. Disabling dynamic mapping might help if mapping is known and doesn't get updated too frequently.
– Nishant Saini
Nov 25 '18 at 14:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462890%2ffilters-with-dynamic-fields-in-elasticsearch%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Wildcard on fields can't be applied on term query. Instead you can use query_string which supports wildcard on field as well. So following will work:
Assuming text_mined_entities and nlp are of type nested
{
"query": {
"nested": {
"path": "text_mined_entities.nlp",
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
}
}
Update (if text_mined_entities & nlp are object type and not nested):
{
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
Thanks! I changed my mapping to be "nested" for both text_mined_entities and nlp ( they were previously "object" ) and that query works. However, would it be possible in the mapping to only index the 'reference' field? It looks like setting this as nested is causing the index size to go up quite a bit.
– fitz
Nov 25 '18 at 12:18
I have added an update with query which should work if the fields areobjecttype. Regarding the possibility to index onlyreferencefield via mapping refer dynamic mapping. Disabling dynamic mapping might help if mapping is known and doesn't get updated too frequently.
– Nishant Saini
Nov 25 '18 at 14:43
add a comment |
Wildcard on fields can't be applied on term query. Instead you can use query_string which supports wildcard on field as well. So following will work:
Assuming text_mined_entities and nlp are of type nested
{
"query": {
"nested": {
"path": "text_mined_entities.nlp",
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
}
}
Update (if text_mined_entities & nlp are object type and not nested):
{
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
Thanks! I changed my mapping to be "nested" for both text_mined_entities and nlp ( they were previously "object" ) and that query works. However, would it be possible in the mapping to only index the 'reference' field? It looks like setting this as nested is causing the index size to go up quite a bit.
– fitz
Nov 25 '18 at 12:18
I have added an update with query which should work if the fields areobjecttype. Regarding the possibility to index onlyreferencefield via mapping refer dynamic mapping. Disabling dynamic mapping might help if mapping is known and doesn't get updated too frequently.
– Nishant Saini
Nov 25 '18 at 14:43
add a comment |
Wildcard on fields can't be applied on term query. Instead you can use query_string which supports wildcard on field as well. So following will work:
Assuming text_mined_entities and nlp are of type nested
{
"query": {
"nested": {
"path": "text_mined_entities.nlp",
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
}
}
Update (if text_mined_entities & nlp are object type and not nested):
{
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
Wildcard on fields can't be applied on term query. Instead you can use query_string which supports wildcard on field as well. So following will work:
Assuming text_mined_entities and nlp are of type nested
{
"query": {
"nested": {
"path": "text_mined_entities.nlp",
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
}
}
Update (if text_mined_entities & nlp are object type and not nested):
{
"query": {
"query_string": {
"query": "BIRNLEX695",
"fields": [
"text_mined_entities.nlp.tagged_entities_grouped.*.reference"
]
}
}
}
edited Nov 25 '18 at 14:34
answered Nov 25 '18 at 3:00
Nishant SainiNishant Saini
1,127818
1,127818
Thanks! I changed my mapping to be "nested" for both text_mined_entities and nlp ( they were previously "object" ) and that query works. However, would it be possible in the mapping to only index the 'reference' field? It looks like setting this as nested is causing the index size to go up quite a bit.
– fitz
Nov 25 '18 at 12:18
I have added an update with query which should work if the fields areobjecttype. Regarding the possibility to index onlyreferencefield via mapping refer dynamic mapping. Disabling dynamic mapping might help if mapping is known and doesn't get updated too frequently.
– Nishant Saini
Nov 25 '18 at 14:43
add a comment |
Thanks! I changed my mapping to be "nested" for both text_mined_entities and nlp ( they were previously "object" ) and that query works. However, would it be possible in the mapping to only index the 'reference' field? It looks like setting this as nested is causing the index size to go up quite a bit.
– fitz
Nov 25 '18 at 12:18
I have added an update with query which should work if the fields areobjecttype. Regarding the possibility to index onlyreferencefield via mapping refer dynamic mapping. Disabling dynamic mapping might help if mapping is known and doesn't get updated too frequently.
– Nishant Saini
Nov 25 '18 at 14:43
Thanks! I changed my mapping to be "nested" for both text_mined_entities and nlp ( they were previously "object" ) and that query works. However, would it be possible in the mapping to only index the 'reference' field? It looks like setting this as nested is causing the index size to go up quite a bit.
– fitz
Nov 25 '18 at 12:18
Thanks! I changed my mapping to be "nested" for both text_mined_entities and nlp ( they were previously "object" ) and that query works. However, would it be possible in the mapping to only index the 'reference' field? It looks like setting this as nested is causing the index size to go up quite a bit.
– fitz
Nov 25 '18 at 12:18
I have added an update with query which should work if the fields are
object type. Regarding the possibility to index only reference field via mapping refer dynamic mapping. Disabling dynamic mapping might help if mapping is known and doesn't get updated too frequently.– Nishant Saini
Nov 25 '18 at 14:43
I have added an update with query which should work if the fields are
object type. Regarding the possibility to index only reference field via mapping refer dynamic mapping. Disabling dynamic mapping might help if mapping is known and doesn't get updated too frequently.– Nishant Saini
Nov 25 '18 at 14:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462890%2ffilters-with-dynamic-fields-in-elasticsearch%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown